package comp418.blingo;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
 * 
 * @author Jingbang
 *
 */
public class create extends Activity {
	private Utility utility=null;
	
	
	private Button bt_raise;
	private Context mContext;
	private EditText title;
	private EditText content;
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.create);
		utility=Utility.getUtility();
		mContext=this;
		
		
		title=(EditText)findViewById(R.id.questiontitle);
		content=(EditText)findViewById(R.id.questioncontent);
		bt_raise=(Button) findViewById(R.id.raise);
		if(bt_raise==null)
			Log.i("show:","ifnull");
		bt_raise.setOnClickListener(new bt_raiseQ());
		
		
		
	}
	
	class bt_raiseQ implements android.view.View.OnClickListener {
		public void onClick(View v) {
			// TODO Auto-generated method stub
			String qtitle=title.getText().toString();
			String qContent=content.getText().toString();
			if(qtitle!=null && qContent!=null && !qtitle.equals("") && !qContent.equals("")){
				//send the question
				//TODO: sending
				//get the id && content...
				int qid=0;
				qid=utility.RaiseQuestion(qtitle, qContent);
				utility.setQid(qid);
				Intent intent=new Intent();
				String user=utility.getUsername();
				intent.setClass(create.this,description.class);
			
				create.this.startActivity(intent);
			}else{
				utility.showToast(mContext, "Please complete all fields!");
			}

		}
	}
}
